<%@page import="java.text.DecimalFormat"%>
<%@page import="cart.CartItem"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.Map" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cae2</title>
</head>
<body>
 <h1>购物车清单</h1>
 <% 
      Map cart=(Map)session.getAttribute("cart");
 
     double total=0;
     if(cart==null||cart.size()==0){
           out.println("购物车为空，您还未点单，请返回");
 }else{
	 Set cartItems=cart.keySet(); 
	 Object[] isbn=cartItems.toArray();//转化为数组
	 //转化的目的做循环
	 CartItem cartItem;
	 TitlesBean book =null;
	 int quantity=0;
	 double price,subtotal;//单价与小计
	 %>

		<table width="590" border="1">
		 <tr>
		   <th>菜名</th>
		   <th>数量</th>
		   <th>价格</th>
		   <th>小计</th>
		 </tr>
	 <% 
		   int i=0;
		   while(i<isbn.length){
			   cartItem=(CartItemBean)cart.get(isbn[i]);
			   book=cartItem.getBook();
			   quantity=cartItem.getQuantity();
			   price =book.getPrice();
			   subtotal=price*quantity;
			   total +=subtotal;
			   i++;
			%>
			<tr>
			<td><%=book.getTitle() %></td>
			<td><%=quantity%></td>
			<td><%=new DecimalFormat("0.00").format(price)%></td>
			<td><%=new DecimalFormat("0.00").format(subtotal)%></td>
			</tr>
		 <% }
		%>
		<tr>
		<td>
		<b>总计：</b>
		<%=new DecimalFormat("0").format(total) %>
		</td>
		</tr>
		</table> 
		<% }
     %>
     <%
     session.setAttribute("total",total);
     %>
</body>
</html>